export default {
    props: {
        selectKey: {
            type: String,
            default: 'id'
        },
        selectName: {
            type: [String, Function],
            default: 'name'
        },
        selectType: {
            type: String,
            default: 'text'
        },
        selection: {
            type: Array,
            default: () => []
        },
        data: {
            type: Array,
            default: () => []
        },
        columns: {
            type: Array,
            default: () => []
            // 示例 {
            //     title:'xxx',
            //     key:'sss',
            //     setColor:fun, //颜色
            //     filter:fun, //显示
            //     type:'' //href
            //     tooltip:true/false(显示和详情一致)
            //     slot:''
            //     oplist:[] //slot action
            // }
        },
        page: {
            type: Number,
            default: 1
        },
        size: {
            type: Number
        },
        total: {
            type: Number,
            default: 0
        },
        loading: {
            type: Boolean,
            default: false
        },
        noDataText: {
            type: String
        },
        rowClassName: {
            type: Function
        },
        showPage: {
            type: Boolean,
            default: true
        },
        showDef: {
            type: Boolean,
            default: true
        },
        showSelectTag: {
            //表格上方显示Tag
            type: Boolean,
            default: false
        },
        maxHeight: {
            type: [String, Number],
            default: 'auto'
        },
        disabled: { //禁用选择
            type: [Boolean,Function],
            default: false,
        },
        showLoading:{
            type:Boolean,
            default:true
        },
        showIndex:{
            type:Boolean,
            default:false
        }
    },
    data(){
        return {
            curPage: this.page || 1,
            pageSize: this.size || 10,
            cloading: false,
            pageSizeOptions:[10,20],
        }
    },
    methods:{
        changePage(page) {
            if(this.isChangeSize){
              this.isChangeSize = false;
              return
            }
            if(this.showLoading){
              this.data.length = this.pageSize + 1;
              this.cloading = true;
            }
            this.curPage = page;
            this.$emit('update:page', page); 
            if(this._events['queryFun']){
              this.$emit('queryFun');
            }else{
              this.$emit('change-page', page);
            }
        },
        changePageSize(size) {
            this.pageSize = size;
            this.$emit('update:size', size);
            let curPage = this.curPage;
            if(curPage !== 1){
                this.isChangeSize = true;
            }
            if(this.total > 0){
              let maxPage = Math.ceil(this.total / size)
              if(maxPage < this.curPage){
                curPage = maxPage
              }
            }
            if(this._events['queryFun']){
              setTimeout(() => {
                this.curPage = curPage;
                this.$emit('update:page',curPage); 
                this.$emit('queryFun');
              })
            }else{
              this.$emit('update:page',curPage); 
              this.$emit('change-size', size);
            }
        },
    }
}